<!--
 * @Author: HeAo
 * @Date: 2022-09-16 14:24:04
 * @LastEditTime: 2022-09-16 14:41:26
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \第二阶段\ES6\day04迭代器\6-async函数.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
  <script>
    // 1、axios
    console.log(axios);
    async function loadAll() {
      // 1、正常发送一个get请求
      // let res = await axios.get('http://121.199.0.35:8888/index/article/findCategoryArticles')
      // console.log(res);

      // 2、try catch finally 发送请求和捕获异常
      try {
        let res = await axios.get('http://121.199.0.35:8888/index/article/findCategoryArticles')
        console.log(res);
      } catch (error) {
        // 告诉别人
        console.log(error);
        // 3、throw error 抛出错误
        throw new Error('请求错误')

      } finally {
        // 无论结果如何 最终都会执行
        console.log('我执行了');
      }
    }
    loadAll()
  </script>
</head>

<body>

</body>

</html>